package com.jwdf.uda.utils;

/**
 * 类说明：字符串操作相关工具类
 * 作者：huangqiuxin on 2016/3/29 09:05
 * 邮箱：648859026@qq.com
 */
public class StringUtils {
    /**
     * 判断是否为空
     *
     * @param str
     * @return
     */
    public static boolean isNullEmpty(String str) {
        if (str == null || "".equals(str.trim())) {
            return true;
        }
        return false;
    }

    /**
     * 过滤掉空字符串以及前后截取空串
     *
     * @param str
     * @return
     */
    public static String filterNullAndTrim(String str) {
        return (str == null ? "" : str.trim());
    }

    /**
     * 请求内容转义
     * (
     * &-----{:chr38:}
     * <p>
     * <p>
     * )
     */
    public static String escParamContent(String content) {
        if (content == null) return "";
        return content.replaceAll("\\&", "{:chr38:}");
    }

    public static String subNickName(String nickName) {
        boolean sub = nickName.length() > 15 ? true : false;
        if (sub) {
            nickName = nickName.substring(0, 15);
            StringBuilder sb = new StringBuilder(nickName);
            return sb.append("...").toString();
        } else {
            return nickName;
        }
    }
}
